import java.util.Comparator;
import java.util.Date;

/**
 * The measurementComparator implements the Comparator function for comparing
 * the time value of two measurement objects
 * 
 * @author Team 10
 * 
 */
public class MeasurementComparator implements Comparator<Measurement> {
	
	/**
	 * Method compares the time value of two measurement objects m1 and m2. 
	 * The value returned is 1 when m1>m2
	 * The value returned is -1 when m1<m2
	 * The value returned is 0 when m1=m2
	 */
	public int compare(Measurement m1, Measurement m2) {
		
		//Retrieve value of date1 from measurement as a long 
		Date date1 = new Date();
		date1 = new Date((Long) m1.getValue(0));
		
		//Retrieve value of date2 from measurement as a long 
		Date date2 = new Date();
		date2 = new Date((Long) m2.getValue(0));
		
		//Start comparing the long values of date 
		long n1 = date1.getTime();
		long n2 = date2.getTime();
		if (n1 < n2)
			return -1;
		else if (n1 > n2)
			return 1;
		else
			return 0;

	}
}
